/*
 * 爱组搭 http://aizuda.com 低代码组件化开发平台
 * ------------------------------------------
 * 受知识产权保护，请勿删除版权申明
 */
package com.aizuda.oss.autoconfigure;

import com.aizuda.common.toolkit.ReflectUtils;
import com.aizuda.oss.IFileStorage;
import com.aizuda.oss.model.StoragePlatform;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * aizuda oss 自动装配
 * <p>
 * 尊重知识产权，CV 请保留版权，爱组搭 http://aizuda.com 出品
 *
 * @author izyao
 * @since 2022/3/22
 */
@Configuration
@EnableConfigurationProperties(OssProperties.class)
public class OssAutoConfiguration {

    private final OssProperties properties;

    public OssAutoConfiguration(OssProperties ossProperties) {
        this.properties = ossProperties;
    }

    @Bean
    @ConditionalOnMissingBean
    public IFileStorage fileStorage() throws Exception {
        IFileStorage fileStorage = ReflectUtils.newInstance(StoragePlatform.getStrategyClass(properties.getPlatform()));
        return fileStorage.init(properties);
    }

}
